<template>
  <div>
    <div id="main"></div>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import * as echarts from "echarts";
export default {
  watch: {
    changeList: {
      deep: true,
      handler() {
        var myChart = echarts.init(document.getElementById("main"));
        // 绘制图表
        myChart.setOption({
          title: {
            text: "ECharts 入门示例",
          },
          tooltip: {},
          xAxis: {
            data: this.changeList.map((item) => item.catename),
          },
          yAxis: {},
          series: [
            {
              name: "销量",
              type: "bar",
              data: this.changeList.map((item) => item.children.length),
            },
          ],
        });
      },
    },
  },
  computed: {
    ...mapGetters({
      changeList: "cate/list",
    }),
  },
  methods: {
    ...mapActions({
      asyncChangeList: "cate/asyncChangeList",
    }),
  },
  mounted() {
    this.asyncChangeList();
  },
};
</script>

<style>
#main {
  width: 50%;
  height: 400px;
  border: 1px solid #ccc;
}
</style>